$(function () {
    useLayUI();
})


var delivery = new Vue({
    el: "#delivery",
    data() {
        return {
            services: services,
            userInfo:'',
            deliveryall:[],//全部
            handlepending:[],     //待处理
            interviewpending:[],    //待面试
            unsuited:[],    //不适合
            admission:[],
            deliveryallcheck : true,
            handlependingcheck : true,
            interviewpendingcheck : true,
            unsuitedcheck : true,
            admissioncheck : true,
        }
    },
    created () {
        this.userInfo = LoginStatus();

    },
    methods:{
    }
});
var pageIndex = 1;
var pageSize = 6;
var deliveryCount = 0;
var handlependingCount = 0;
var interviewpendingCount = 0;
var unsuitedCount = 0;
var admissionCount = 0;
var _url = '/user/resume/delivery/list';

pagination('delivery',pageIndex,'', pageSize,'get',_url)
layuipage('delivery_pagination','delivery',pageIndex,'',pageSize,'get',_url,deliveryCount)

pagination('handlepending',pageIndex,1, pageSize,'get',_url)
layuipage('handlepending_pagination','handlepending',pageIndex,1,pageSize,'get',_url,handlependingCount)
pagination('interviewpending',pageIndex,2, pageSize,'get',_url)
layuipage('interviewpending_pagination','interviewpending',pageIndex,2,pageSize,'get',_url,interviewpendingCount)
pagination('unsuited',pageIndex,4, pageSize,'get',_url)
layuipage('unsuited_pagination','unsuited',pageIndex,4,pageSize,'get',_url,unsuitedCount)

pagination('admission',pageIndex,3, pageSize,'get',_url)
layuipage('admission_pagination','admission',pageIndex,3,pageSize,'get',_url,admissionCount)

//使用layui分页方法
function layuipage(_pageid,_id,pageIndex,status, pageSize,_type,_url,Count){
    layui.use('laypage', function () {
        var laypage = layui.laypage;
        laypage.render({
            elem: _pageid
             , count: Count
            ,limit:pageSize//每页的条数
            , layout: ['count', 'prev', 'page', 'next', 'skip']
            , jump: function (obj, first) {

                //点击非第一页页码时的处理逻辑。比如这里调用了ajax方法，异步获取分页数据
                if (!first) {
                    pagination(_id,obj.curr,status,obj.limit,_type,_url);//第二个参数不能用变量pageSize，因为当切换每页大小的时候会出问题
                }
            }
        });
    });

}

//ajax渲染
function pagination(_id,pageIndex,status, pageSize,_type,_url) {
    var param = {
        page: pageIndex,
        limit: pageSize,
        status:status,
    };
   
    $.ajax({
        type: _type,
        async:false,
        url: services+_url,
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        data:param,
        success: function (res) {
            var obj = JSON.parse(res)
            if(obj.code==0){
                if(obj.count==0){
                    if(_id=="delivery"){
                        delivery.deliveryallcheck = false;
                    }else if(_id=="handlepending"){                      
                        delivery.handlependingcheck = false;
                    }else if(_id=="interviewpending"){             
                        delivery.interviewpendingcheck = false;
                    }else if(_id=="unsuited"){
                        delivery.unsuitedcheck = false;
                    } else if(_id=="admission"){
                        delivery.admissioncheck = false;
                    }
                }else{
                    if(_id=="delivery"){
                        deliveryCount = obj.count;
                        delivery.deliveryall = obj.data;
                    }else if(_id=="handlepending"){
                        handlependingCount = obj.count;
                        delivery.handlepending = obj.data;
                    }else if(_id=="interviewpending"){
                        // console.log(_id)  
                        interviewpendingCount = obj.count;
                        delivery.interviewpending = obj.data;
                    }else if(_id=="unsuited") {
                        unsuitedCount = obj.count;
                        delivery.unsuited = obj.data;
                    }else if(_id=="admission"){
                        admissionCount = obj.count;
                        delivery.admission = obj.data;
                    }
                }
            }        
        }
    });
};


